const express = require("express");
const fs = require("fs");
let adminRouter = express.Router();
adminRouter.get("/addProduct",(req,res)=>{
    res.render("addProduct.ejs");
})
adminRouter.post("/addData",(req,res)=>{
    if(!fs.existsSync("./data")){
        fs.mkdirSync("./data",0777);
    }

    if(!fs.existsSync("./data/product.json")){
        fs.writeFileSync("./data/product.json",JSON.stringify([]));
    }
    let data = JSON.parse(fs.readFileSync("./data/product.json"));
     .id = data.length+1;
    req.body.imgurl = "/images/超.jpg"


    data.push(req.body);
    fs.writeFileSync("./data/product.json",JSON.stringify(data));
    res.send("添加成功")
})

module.exports = adminRouter;